package com.hq.learnmybatisplus.inject;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.extension.injector.methods.additional.InsertBatchSomeColumn;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义sql注入器  把自定义的通用sql 放入mp的通用mapper中
 * @see SqlDeleteAllMethod
 * @see com.hq.learnmybatisplus.SqlInjectTest
 * @author MAIBENBEN
 */
@Component
public class MySqlInject extends DefaultSqlInjector {


    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        //获取父类中的所有通用方法 然后在添加自定义的 SqlDeleteAllMethod
        List<AbstractMethod> methodList = super.getMethodList(mapperClass);
        methodList.add(new SqlDeleteAllMethod());

        //排除逻辑删除的字段 其他都新增 参与
        methodList.add(new InsertBatchSomeColumn(t -> !t.isLogicDelete()));
        return methodList;
    }
}
